/*
 * txdnet.cn tonydon
 * by netbeans ide 7.2
 */
package cn.txdnet.txcms.dao;

import cn.txdnet.txcms.domain.Links;
import cn.txdnet.txcms.dto.PageDTO;
import cn.txdnet.txcms.mapper.LinksMapper;
import cn.txdnet.txcms.query.LinksQuery;
import cn.txdnet.txweb.utils.CollectionUtil;
import java.util.List;
import java.util.Map;

/**
 *
 * @author tangxiaodong
 */
public class LinksDAO extends MybatisBaseDAO {

    /**
     * 新建链接
     *
     * @param lk
     * @return
     */
    public int insertLink(Links lk) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.insertLink(lk);
    }

    /**
     * 删除单个链接
     *
     * @param lkid
     * @return
     */
    public int deleteLink(int[] ida) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.deleteLink(ida);
    }

    /**
     * 更新链接信息
     *
     * @param lk
     * @return
     */
    public int updateLink(Links lk) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.updateLink(lk);
    }

    /**
     * 更新发布状态
     *
     * @param m
     * @return
     */
    public int updatePubstate(Map<String, Object> m) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.updatePubstate(m);
    }

    /**
     * 更新权重
     *
     * @param m
     * @return
     */
    public int updateWeight(Map<String, Object> m) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.updateWeight(m);
    }

    /**
     * 批量更新类目
     *
     * @param m
     * @return
     */
    public int updateCatalog(Map m) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.updateCatalog(m);
    }

    /**
     * 查询最大权重值
     *
     * @return
     */
    public int queryMaxWeight() {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.queryMaxWeight();
    }

    /**
     * 查询链接
     *
     * @param lkid
     * @return
     */
    public Links queryLink(int lkid) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        return mapper.queryLink(lkid);
    }

    /**
     * 查询链接记录
     *
     * @param query
     * @return
     */
    public PageDTO queryByFactor(LinksQuery query) {
        LinksMapper mapper = this.getMapper(LinksMapper.class);
        query.filter();
        List list = mapper.listByFactor(query);
        if (query.getRownum().intValue() == 0 && CollectionUtil.isNotEmpty(list)) {
            query.setRownum(mapper.countByFactor(query));
        }
        return new PageDTO(list, query.getRownum());
    }
}
